﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Web;

namespace WmsService.Reports
{
    public class ReportWrap
    {
    
        public Report FReport { get; set; }
        public List<ReportDetail> FReportDetailList { get; set; }
        public void HandleAopDataSet(DataSet ds)
        {
            if(FReport!= null && FReportDetailList != null)
            {
                if(!String.IsNullOrEmpty(FReport.ExtVarChar1))
                {
                    try
                    {
                        var assembly = string.Empty;
                        //如果存在"."，就认为是配置了class的全名，否则就默认在WmsService.Reports命名空间下
                        if(FReport.ExtVarChar1.Contains("."))
                        {
                            assembly = FReport.ExtVarChar1;
                        }
                        else
                        {
                            assembly = "WmsService.Reports." + FReport.ExtVarChar1;
                        }
                        var aopHandle = (IReportAopHandle)Assembly.GetAssembly(typeof(ReportWrap)).CreateInstance(assembly);
                        aopHandle.Handle(ds, FReportDetailList);
                    }
                    catch (Exception exception)
                    {
                        Exceptions.ExceptionHandler.ThrowException("创建动态对象失败，可能是Report.ExtVarChar1字段配置错误！" + exception.Message);
                    }
                }
            }
        }
    }
}